<?php


namespace app\api\validate;


use think\Validate;

class UserValidate extends Validate
{
    //定义验证规则
    protected $rule = [
        'user_name' => 'max:20|requireIf:account_type,2',
        'school_name' => 'max:30|requireIf:account_type,2',
        'school_address' => 'max:50|requireIf:account_type,2',
        'mobile' => 'require|mobile',//|unique:user
        'password' => 'require|max:32',
        'account_type' => 'require',
        'status' => 'require',
        'code' => 'requireIf:account_type,1',
    ];
    //定义验证失败时的提示信息
    protected $message = [
        'user_name.require' => '用户名不能为空',
        'user_name.max:20' => '用户名最多不能超过20个字符',
        'user_name.requireIf:account_type,2' => '用户名仅用于教师注册',
        'school_name.require' => '学校名称不能为空',
        'school_name.max:30' => '学校名称最多不能超过30个字符',
        'school_name.requireIf:ccount_type,2' => '学校名称仅用于教师注册',
        'school_address.require' => '学校地址不能为空',
        'school_address.max:50' => '学校地址最多不能超过50个字符',
        'school_address.requireIf:user,account_type,2' => '学校地址仅用于教师注册',
        'mobile.require' => '手机号不能为空',
        'mobile.mobile' => '手机号格式错误',
       // 'mobile.unique:user' => '手机号已存在',
        'password.require' => '密码不能为空',
        'password.max:32' => '密码最多不能超过32个字符',
        'account_type.require' => '账号类型不能为空',
        'status.require' => '状态不能为空',
        'status.integer' => '状态必须是整数',
        'id.require' => 'id不能为空'
    ];

    //验证场景
    protected  $scene = [
        'register' => ['user_name','school_name','school_address','mobile','password','account_type','status'],
        'login' => ['mobile','password','code'],
    ];
}